const friendLinkDao = require("@/dao/friend_link");
const z_base_Dao = require("@/dao/z_base");
const FriendLinkModal = require("@/model/FriendLink");
const { ErrorCode } = require("@/utils/r/code");
const { cloneDeep } = require("lodash");

const link = {
  async GetList(data) {
    const { pageData, total } = await friendLinkDao.GetList(data);
    return {
      pageData,
      total,
      pageNum: +data.page_num,
      pageSize: +data.page_size,
    };
  },
  async SaveOrUpdate(body) {
    let friendLink = cloneDeep(body);
    //根据id决定是否更新
    friendLink.updated_at = new Date().toLocaleString();
    if (friendLink.id) {
      //更新
      await z_base_Dao.Update(FriendLinkModal.friendLink, friendLink, {
        id: friendLink.id,
      });
    } else {
      friendLink.created_at = new Date().toLocaleString();
      await z_base_Dao.Create(FriendLinkModal.friendLink, friendLink);
    }
    return ErrorCode.OK;
  },
  async Delete(ids) {
    await z_base_Dao.Delete(FriendLinkModal.friendLink, { id: ids });
    return ErrorCode.OK;
  },
  async GetFrontList() {
    const result = await z_base_Dao.List(FriendLinkModal.friendLink);
    return result;
  },
};

module.exports = link;
